package com.itshare.video.controller;

import com.itshare.video.aop.annontations.AccountFreezeCheck;
import com.itshare.video.common.annontation.AttrData;
import com.itshare.video.common.dto.Result;
import com.itshare.video.common.util.QiniuUtils;
import com.itshare.video.pojo.dto.UserTokenDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

/**
 * @Author lyr
 * @create 2020/10/24 10:25
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/api/")
public class FileController {

    @Resource
    private QiniuUtils qiniuUtils;

    @AccountFreezeCheck
    @PostMapping("/upload")
    public Result uploadFile(@RequestPart("file") MultipartFile file, @AttrData UserTokenDTO userTokenDTO) {
        log.info("用户 id {},role{}",userTokenDTO.getId(),userTokenDTO.getRole());

        return qiniuUtils.uploadFile(file);
    }









}
